package work;
import java.util.Random;
import javax.swing.ImageIcon;
import java.awt.Graphics;
//公共父类
public abstract class SeaObject {
    public static final int LIVE =0;
    public static final int DEAD =1;
    protected int state = LIVE;

    protected int width;
    protected int height;
    protected int x;
    protected int y;
    protected int speed;

    //潜艇宽高不一样其他一样
    public SeaObject(int width,int height){
        this.width = width;
        this.height = height;
        x = -width;
        Random rand =new Random();
        y = rand.nextInt(479-height-150+1)+150;
        speed = rand.nextInt(3)+1;
    }
    public SeaObject(int width,int height,int x,int y,int speed){
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }
    public abstract void move();

    //获取对象图片
    public abstract ImageIcon getImage();

    public boolean isLive(){
        return state==LIVE;
    }
    public boolean isDead(){
        return state==DEAD;
    }

    public void paintImage(Graphics g){
        if (isLive()){
            this.getImage().paintIcon(null,g,this.x,this.y);
        }
    }


}
